package spring.boot.service.impl;




import spring.boot.mapper.LoginMapper;
import spring.boot.po.AgentUserEntity;
import spring.boot.po.Message;
import spring.boot.po.Messages;
import spring.boot.po.UserHomeEntity;
import spring.boot.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.DEFAULT,timeout=5)
@Service("loginservice")
public class LoginServiceImpl implements LoginService {
	@SuppressWarnings("all")
	@Autowired
	LoginMapper loginmapper;

	public String getpwdbyname(Integer uid) {
		UserHomeEntity userHomeEntity=loginmapper.getpwdbyname(uid);
		System.out.println(userHomeEntity.toString());
		if(userHomeEntity!=null)
			return userHomeEntity.getUserPwd()+"";
		else
			return null;
	}

	public Integer getUidbyname(Integer uid) {
		UserHomeEntity userHomeEntity = loginmapper.getpwdbyname(uid);
		System.out.println(userHomeEntity.toString());
		if (userHomeEntity != null) {
			Integer userId = userHomeEntity.getUserId();
			System.out.println(userId);
			return  userId;
		}else{

			return null;
		}
	}

	public String getnamebyid(Integer id) {
		System.out.println(id);
		UserHomeEntity s=loginmapper.getnamebyid(id);

		System.out.println("这是查到的对象："+s.toString());
		if(s!=null)
			return s.getUserName();
		else
			return null;
	}

	@Override
	public AgentUserEntity getagent(Integer aid) {
		AgentUserEntity getagent = loginmapper.getagent(aid);
		System.out.println(getagent);
		return getagent;
	}

	@Override
	public void savemsgs(ArrayList<Message> msgs) {
		loginmapper.savemsgs(msgs);
	}

    @Override
    public List<Messages> selmsgs(String to, String from) {

		return loginmapper.selmsgs(to,from);
    }


}
